package com.college.eduorder.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.college.commonutils.R;
import com.college.eduorder.service.PayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-08-27
 */
@RestController
@RequestMapping("/eduorder/paylog")
@CrossOrigin
public class PayLogController {
    @Autowired
    private PayLogService payLogService;

    //生成二维码接口
    @GetMapping("/createNative/{orderNo}")
    public R createNative(@PathVariable String orderNo) {
        //返回二维码地址和其他信息
        Map map = payLogService.createNative(orderNo);
        System.out.println("(((((((((((("+map);
        return R.ok().data(map);
    }

    //获取支付状态
    @GetMapping("/getPayStatus/{orderId}")
    public R getPayStatus(@PathVariable String orderId) {
        Map<String,String> map = payLogService.getPayStatus(orderId);
        System.out.println("))))))))))))))"+map);
        if (map == null){
            return R.error().message("支付出错了");
        }
        if (map.get("trade_state").equals("SUCCESS")){
            //添加记录到支付表，更新订单接口状态
            payLogService.updateOrderStatus(map);
            return R.ok().message("支付成功");
        }

        return R.ok().code(25000).message("支付中");
    }
}

